home *** CD-ROM | disk | FTP | other *** search
/ Freaks Macintosh Archive / Freaks Macintosh Archive.bin / Freaks Macintosh Archives / Textfiles / zines / Phrack / Phrack Issue 51.sit / Phrack51 / P51-17 < prev   
Text File  |  1997-09-01  |  3KB  |  111 lines

  1. ---[  Phrack Magazine   Volume 7, Issue 51 September 01, 1997, article 17 of 17
  2.  
  3.  
  4. -------------------------[  Phrack Magzine Extraction Utility
  5.  
  6.  
  7. --------[  Phrack Staff
  8.  
  9.     This time around, you have the option of using the C version of extract, 
  10. or the PERL version, contributed by Daos.
  11.  
  12.  
  13. ---------------------8<------------CUT-HERE----------->8---------------------
  14.  
  15. /*  extract.c by Phrack Staff and sirsyko 
  16.  *
  17.  *  (c) Phrack Magazine, 1997 
  18.  *
  19.  *  Extracts textfiles from a specially tagged flatfile into a hierarchical 
  20.  *  directory strcuture. Use to extract source code from any of the articles 
  21.  *  in Phrack Magazine (first appeared in Phrack 50).
  22.  *
  23.  *  gcc -o extract extract.c
  24.  *  
  25.  *  ./extract filename   
  26.  */   
  27.  
  28.  
  29. #include <stdio.h>
  30. #include <sys/stat.h>
  31. #include <string.h>
  32.  
  33. int main(int argc, char **argv){ 
  34.  
  35.     char *s="<++> ",*e="<-->",b[256],*bp; 
  36.     FILE *f,*o = NULL; 
  37.     int l, n, i=0; 
  38.  
  39.     l = strlen(s); 
  40.     n = strlen(e); 
  41.  
  42.     if(argc<2) {
  43.         printf("Usage: %s <inputfile>\n",argv[0]);
  44.         exit(1); 
  45.     }
  46.  
  47.     if(! (f=fopen(argv[1], "r"))) {
  48.         printf("Could not open input file.\n");
  49.     exit(1);
  50.     }
  51.  
  52.     while(fgets(b, 256, f)){ 
  53.  
  54.         if(!strncmp (b, s, l)){ 
  55.         b[strlen(b)-1] = '\0'; 
  56.  
  57.         if((bp=strchr(b+l+1,'/')))
  58.             while (bp){ 
  59.             *bp='\0';
  60.             mkdir(b+l, 0700); 
  61.             *bp='/';
  62.             bp=strchr(bp+1,'/'); 
  63.         }
  64.         if((o = fopen(b+l, "w"))) 
  65.             printf("- Extracting %s\n",b+l);
  66.         else {
  67.         printf("Could not extract '%s'\n",b+l);
  68.         exit(1);
  69.         }
  70.     } 
  71.         else if(!strncmp (b, e, n)){
  72.         if(o) fclose(o);
  73.         else {
  74.             printf("Error closing file.\n");
  75.         exit(1);
  76.         }
  77.         } 
  78.         else if(o) {
  79.             fputs(b, o);
  80.             i++;
  81.         }
  82.     }
  83.     if(!i) printf("No extraction tags found.\n");
  84.     return(0);
  85. }
  86.  
  87. ---------------------8<------------CUT-HERE----------->8---------------------
  88.  
  89. # Daos <daos@nym.alias.net>
  90.  
  91. <++> extract.pl
  92. #!/bin/sh -- # -*- perl -*- -n
  93. eval 'exec perl $0 -S ${1+"$@"}' if 0;
  94.  
  95. $opening=0;
  96.  
  97. if (/^\<\+\+\>/) {$curfile = substr($_ , 5); $opening=1;};
  98. if (/^\<\-\-\>/) {close ct_ex; $opened=0;}; 
  99. if ($opening) {                        
  100.         chop $curfile;                 
  101.         $sex_dir= substr( $curfile, 0, ((rindex($curfile,'/'))) ) if ($curfile =~ m/\//);
  102.         eval {mkdir $sex_dir, "0777";}; 
  103.         open(ct_ex,">$curfile"); 
  104.         print "Attempting extraction of $curfile\n";
  105.         $opened=1; 
  106. }
  107. if ($opened && !$opening) {print ct_ex $_}; 
  108. <-->
  109.  
  110. ----[  EOF
  111.